package week04.bank;
/*
    A checking account that charges transaction fees.
*/
 public class ContCredit extends ContBancar
 {
    /**
       Constructs a checking account with a given balance.
       @param initialBalance the initial balance
    */
    public ContCredit(double soldInitial)
    {
       // Construct superclass
       super(soldInitial);

       // Initialize transaction count
       contorTranzactii = 0;
    }

    public void depunere(double suma)
    {
       contorTranzactii++;
       // Now add amount to balance
       super.depunere(suma);
    }

    public void retragere(double suma)
    {
       contorTranzactii++;
       // Now subtract amount from balance
       super.retragere(suma);
    }

    /**
       Deducts the accumulated fees and resets the
       transaction count.
    */
    public void taxareTranzactie()
    {
       /* TAXA = TOTAL_TAXE_PT_TOATE_TRANZACTIILE
          TAXA = TAXA_PER_UNA_TRANZACTIE * TRANZACTII_TAXABILE
          TRANZACTII_TAXABILE = TOTAL_TRANZACTII - TRANZACTII_GRATUITE
       */
       if (contorTranzactii > TRANZACTII_GRATUITE)
       {
          double   taxa = TAXAPERTRANZACTIE *
                (contorTranzactii - TRANZACTII_GRATUITE);
          super.retragere(taxa);
       }
       contorTranzactii = 0;
    }

    private int contorTranzactii;

    private static final int TRANZACTII_GRATUITE = 3;
    private static final double TAXAPERTRANZACTIE = 2.0;
 }